import { Sprite_Canvas } from "@/sprites/Sprite_Canvas.js";
import { ColorExtraction } from "@/utils/ColorExtraction.js";

export class Sprite_MapName extends Sprite_Canvas{
    constructor(width,height){
        super(width,height);
        this.isFading=false;
        this.direct=0;
        this.drawMapName();
    }

    update(){
        super.update();
        if(this.isFading){
            let alpha=this.alpha+this.direct;
            if(alpha<=0){
                this.alpha=0;
                this.visible=false;
                this.isFading=false;
            }else if(alpha>=1){
                this.alpha=1;
                this.isFading=false;
            }else{
                this.alpha=alpha;
            }
        }
    }

    show(){
        this.visible=true;
        this.alpha=0;
        this.isFading=true;
        this.direct=1/30;
    }

    close(){
        this.alpha=1;
        this.isFading=true;
        this.direct=-1/30;
    }

    isBusy(){
        return this.duration>0;
    }

    drawMapName(){
        let color1 = ColorExtraction.dimColor1();
        let color2 = ColorExtraction.dimColor2();
        this.gradientFillRect(x, y, width / 2, height, color2, color1);
        this.gradientFillRect(x + width / 2, y, width / 2, height, color1, color2);
        this.drawText($gameMap.displayName(), 0, 0, width,this.height, 'center');
    }
}